3c468b2c485752a4d9bf62cffb12903c9781a8cc,src/main/java/net/sf/oval/Validator.java,Validator,_addChecks,#ClassChecks#ClassConfiguration#,329
Before Change
* ******************************/
if (classCfg.methodConfigurations != null)
{
for (final MethodConfiguration methodCfg : classCfg.methodConfigurations)
{
/* ******************************
* determine the method
* ******************************/
final Method method;
if (methodCfg.parameterConfigurations == null || methodCfg.parameterConfigurations.size() == 0)
{
method = classCfg.type.getDeclaredMethod(methodCfg.name);
}
else
{
final Class< ? >[] paramTypes = new Class[methodCfg.parameterConfigurations.size()];
for (int i = 0, l = methodCfg.parameterConfigurations.size(); i < l; i++)
{
paramTypes[i] = methodCfg.parameterConfigurations.get(i).type;
}
method = classCfg.type.getDeclaredMethod(methodCfg.name, paramTypes);
}
if (TRUE.equals(methodCfg.overwrite))
{
cc.clearMethodChecks(method);
}
/* ******************************
* applying field constraints to the single parameter of setter methods
* ******************************/
if (applyFieldConstraintsToSetters)
{
final Field field = ReflectionUtils.getFieldForSetter(method);
// check if a corresponding field has been found
if (field != null)
{
final AssertFieldConstraintsCheck check = new AssertFieldConstraintsCheck();
check.setFieldName(field.getName());
cc.addMethodParameterChecks(method, 0, check);
}
}
/* ******************************
* configure parameter constraints
* ******************************/
if (methodCfg.parameterConfigurations != null && methodCfg.parameterConfigurations.size() > 0)
{
for (int i = 0, l = methodCfg.parameterConfigurations.size(); i < l; i++)
{
final ParameterConfiguration paramCfg = methodCfg.parameterConfigurations.get(i);
if (TRUE.equals(paramCfg.overwrite))
{
cc.clearMethodParameterChecks(method, i);
}
if (paramCfg.hasChecks())
{
cc.addMethodParameterChecks(method, i, paramCfg.checks);
}
if (paramCfg.hasCheckExclusions())
{
cc.addMethodParameterCheckExclusions(method, i, paramCfg.checkExclusions);
}
if (assertParametersNotNull)
{
cc.addMethodParameterChecks(method, i, sharedNotNullCheck);
}
}
}
/* ******************************
* configure return value constraints
* ******************************/
if (methodCfg.returnValueConfiguration != null)
{
if (TRUE.equals(methodCfg.returnValueConfiguration.overwrite))
{
cc.clearMethodReturnValueChecks(method);
}
if (methodCfg.returnValueConfiguration.checks != null
&& methodCfg.returnValueConfiguration.checks.size() > 0)
{
cc.addMethodReturnValueChecks(method, methodCfg.isInvariant,
methodCfg.returnValueConfiguration.checks);
}
}
if (TRUE.equals(methodCfg.preCheckInvariants))
{
cc.methodsWithCheckInvariantsPre.add(method);
}
/*
* configure pre conditions
*/
if (methodCfg.preExecutionConfiguration != null)
{
if (TRUE.equals(methodCfg.preExecutionConfiguration.overwrite))
{
cc.clearMethodPreChecks(method);
}
if (methodCfg.preExecutionConfiguration.checks != null
&& methodCfg.preExecutionConfiguration.checks.size() > 0)
{
cc.addMethodPreChecks(method, methodCfg.preExecutionConfiguration.checks);
}
}
if (TRUE.equals(methodCfg.postCheckInvariants))
{
cc.methodsWithCheckInvariantsPost.add(method);
}
/*
* configure post conditions
*/
if (methodCfg.postExecutionConfiguration != null)
{
if (TRUE.equals(methodCfg.postExecutionConfiguration.overwrite))
{
cc.clearMethodPostChecks(method);
}
if (methodCfg.postExecutionConfiguration.checks != null
&& methodCfg.postExecutionConfiguration.checks.size() > 0)
{
cc.addMethodPostChecks(method, methodCfg.postExecutionConfiguration.checks);
}
}
}
After Change
* apply method parameter and return value checks and pre/post conditions
* ******************************/
if (classCfg.methodConfigurations != null)
for (final MethodConfiguration methodCfg : classCfg.methodConfigurations)
{
/* ******************************
* determine the method
* ******************************/
final Method method;
if (methodCfg.parameterConfigurations == null || methodCfg.parameterConfigurations.size() == 0)
method = classCfg.type.getDeclaredMethod(methodCfg.name);
else
{
final Class< ? >[] paramTypes = new Class[methodCfg.parameterConfigurations.size()];
for (int i = 0, l = methodCfg.parameterConfigurations.size(); i < l; i++)
paramTypes[i] = methodCfg.parameterConfigurations.get(i).type;
method = classCfg.type.getDeclaredMethod(methodCfg.name, paramTypes);
}
if (TRUE.equals(methodCfg.overwrite)) cc.clearMethodChecks(method);
/* ******************************
* applying field constraints to the single parameter of setter methods
* ******************************/
if (applyFieldConstraintsToSetters)
{
final Field field = ReflectionUtils.getFieldForSetter(method);
// check if a corresponding field has been found
if (field != null)
{
final AssertFieldConstraintsCheck check = new AssertFieldConstraintsCheck();
check.setFieldName(field.getName());
cc.addMethodParameterChecks(method, 0, check);
}
}
/* ******************************
* configure parameter constraints
* ******************************/
if (methodCfg.parameterConfigurations != null && methodCfg.parameterConfigurations.size() > 0)
for (int i = 0, l = methodCfg.parameterConfigurations.size(); i < l; i++)
{
final ParameterConfiguration paramCfg = methodCfg.parameterConfigurations.get(i);
if (TRUE.equals(paramCfg.overwrite)) cc.clearMethodParameterChecks(method, i);
if (paramCfg.hasChecks()) cc.addMethodParameterChecks(method, i, paramCfg.checks);
if (paramCfg.hasCheckExclusions())
cc.addMethodParameterCheckExclusions(method, i, paramCfg.checkExclusions);
if (assertParametersNotNull) cc.addMethodParameterChecks(method, i, sharedNotNullCheck);
}
/* ******************************
* configure return value constraints
* ******************************/
if (methodCfg.returnValueConfiguration != null)
{
if (TRUE.equals(methodCfg.returnValueConfiguration.overwrite))
cc.clearMethodReturnValueChecks(method);
if (methodCfg.returnValueConfiguration.checks != null
&& methodCfg.returnValueConfiguration.checks.size() > 0)
cc.addMethodReturnValueChecks(method, methodCfg.isInvariant,
methodCfg.returnValueConfiguration.checks);
}
if (TRUE.equals(methodCfg.preCheckInvariants)) cc.methodsWithCheckInvariantsPre.add(method);
/*
* configure pre conditions
*/
if (methodCfg.preExecutionConfiguration != null)
{
if (TRUE.equals(methodCfg.preExecutionConfiguration.overwrite))
cc.clearMethodPreChecks(method);
if (methodCfg.preExecutionConfiguration.checks != null
&& methodCfg.preExecutionConfiguration.checks.size() > 0)
cc.addMethodPreChecks(method, methodCfg.preExecutionConfiguration.checks);
}
if (TRUE.equals(methodCfg.postCheckInvariants)) cc.methodsWithCheckInvariantsPost.add(method);
/*
* configure post conditions
*/
if (methodCfg.postExecutionConfiguration != null)
{
if (TRUE.equals(methodCfg.postExecutionConfiguration.overwrite))
cc.clearMethodPostChecks(method);
if (methodCfg.postExecutionConfiguration.checks != null
&& methodCfg.postExecutionConfiguration.checks.size() > 0)
cc.addMethodPostChecks(method, methodCfg.postExecutionConfiguration.checks);
}
}
}